<template>
  <!-- 一条文章单元格 -->
  <van-cell>
    <!-- 标题区域的插槽 -->
    <template #title>
      <div class="title-box">
        <!-- 标题 -->
        <span>{{ articleItem.title }}</span>
        <!-- 单图 -->
        <img
          v-lazy="articleItem.cover.images[0]"
          v-if="articleItem.cover.type === 1"
          class="thumb"
          alt=""
        />
      </div>
      <!-- 多图 -->
      <div v-if="articleItem.cover.type > 1" class="thumb-box">
        <img
          v-lazy="imgSrc"
          v-for="(imgSrc, index) in articleItem.cover.images"
          :key="index"
          class="thumb"
          alt=""
        />
      </div>
    </template>
    <!-- label 区域的插槽 -->
    <template #label>
      <div class="label-box">
        <div>
          <span>{{ articleItem.aut_name }}</span>
          <span>{{ articleItem.comm_count }}评论</span>
          <span>{{ formatData(articleItem.pubdate) }}</span>
        </div>
        <!-- 反馈按钮 -->
        <van-icon
          name="cross"
          @click.stop="fankuiFn(articleItem.art_id)"
          v-show="isShow"
        />
      </div>
    </template>
  </van-cell>
</template>

<script>
import dayjs from 'dayjs'
import * as relativeTime from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn'

// 映射使用
import { mapMutations } from 'vuex'

// 插件
dayjs.locale('zh-cn') // use locale
dayjs.extend(relativeTime)
export default {
  props: {
    articleItem: {},
    isShow: {
      type: Boolean,
      default: true // 默认值
    }
  },

  methods: {
    ...mapMutations(['changeActionMutations', 'artIdMutations']),

    formatData (dataStr) {
      var a = dayjs()
      var b = dayjs(dataStr)
      const c = a.to(b)
      console.log(c)
      return c
    },
    // 反馈按钮
    fankuiFn (id) {
      console.log(this.articleItem)
      this.changeActionMutations(true)
      this.artIdMutations(id)
    }
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}
/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}
/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
